<!--
 * @Description: 编辑
 * @Author: zhailei
 * @Date: 2021-01-18 15:17:26
 * @LastEditTime: 2021-09-02 17:03:48
 * 
 * @FilePath: \vite-demoe:\wwwroot\Vue\\-cloud-vue\src\components\TopVUI\bpmn\panel\modal\edit.vue
-->
<template>
  <t-modal
    :title="title"
    :width="640"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleOk"
    @cancel="
      () => {
        $emit('cancel');
      }
    "
  >
    <a-spin :spinning="loading">
      <a-form :form="form">
        <a-form-item>
          <a-input v-decorator="['uuid']" type="hidden" />
        </a-form-item>
        <a-form-item label="事件" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            v-decorator="[
              'event',
              { rules: [{ required: true, message: '请选择事件！' }] },
            ]"
            allowClear
            v-if="type === 1"
            placeholder="请选择事件"
          >
            <a-select-option value="start">
              start(启动)
            </a-select-option>
            <a-select-option value="end">
              end(结束)
            </a-select-option>
            <a-select-option value="take">
              take(在用)
            </a-select-option>
          </a-select>
          <a-select
            v-decorator="[
              'event',
              { rules: [{ required: true, message: '请选择事件！' }] },
            ]"
            allowClear
            v-else
            placeholder="请选择事件"
          >
            <a-select-option value="create">
              create(在任务被创建且所有的任务属性设置完成后才触发)
            </a-select-option>
            <a-select-option value="assignment">
              assignment(在任务被分配给某个办理人之后触发)
            </a-select-option>
            <a-select-option value="complete">
              complete(在配置了监听器的上一个任务完成时触发)
            </a-select-option>
            <a-select-option value="delete">
              delete(在任务即将被删除前触发。请注意任务由completeTask正常完成时也会触发)
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select
            v-decorator="[
              'type',
              { rules: [{ required: true, message: '请选择类型！' }] },
            ]"
            allowClear
            placeholder="请选择类型"
          >
            <a-select-option value="class">
              类(写全限定类名)
            </a-select-option>
            <!-- <a-select-option value="expression">
              表达式(写注入到Spring中Bean名称，如：${testEventListener})
            </a-select-option>
            <a-select-option value="delegateExpression">
              委托表达式
            </a-select-option> -->
          </a-select>
        </a-form-item>
        <a-form-item
          label="java类名"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-textarea
            placeholder="请输入类名"
            :rows="4"
            v-decorator="[
              'className',
              {
                rules: [
                  {
                    required: true,
                    min: 1,
                    message: '请输入至少一个字符的名称！',
                  },
                ],
              },
            ]"
          />
        </a-form-item>
        <!-- <a-form-item label="参数" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['params']" />
        </a-form-item> -->
      </a-form>
    </a-spin>
  </t-modal>
</template>

<script>
import { TreeSelect } from "ant-design-vue";
import pick from "lodash.pick";
const SHOW_PARENT = TreeSelect.SHOW_PARENT;
// 表单字段
const fields = ["uuid", "event", "type", "className"];
export default {
  props: {
    visible: {
      type: Boolean,
      required: true,
    },
    loading: {
      type: Boolean,
      default: () => false,
    },
    model: {
      type: Object,
      default: () => null,
    },
    type: {
      type: Number,
    },
  },
  data() {
    return {
      title: "新增编辑",
      labelCol: {
        xs: {
          span: 24,
        },
        sm: {
          span: 7,
        },
      },
      wrapperCol: {
        xs: {
          span: 24,
        },
        sm: {
          span: 13,
        },
      },
      form: this.$form.createForm(this),
    };
  },
  created() {
    // 防止表单未注册
    fields.forEach((v) => this.form.getFieldDecorator(v));
    // 当 model 发生改变时，为表单设置值
    this.$watch("model", () => {
      this.model && this.form.setFieldsValue(pick(this.model, fields));
    });
  },
  methods: {
    handleOk() {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.$emit("ok");
        }
      });
    },
  },
};
</script>
